<template>
	<view class="main">
		<view>
			<view class="myset">
				<view class="bg_f menu_list_b">
					<navigator url="loginpw">
						<view class="box_li myli" >
							<view>
								修改登录密码
							</view>
							<icon class=" uni app-qianjin2"></icon>
						</view>
					</navigator>
					
					<navigator url="">
						<view class="box_li myli" >
							<view>
								修改交易密码
							</view>
							<icon class=" uni app-qianjin2"></icon>
						</view>
					</navigator>
					
					<view class="box_li myli" @click="cacheSize">
						<view>
							清理缓存
						</view>
						<icon class=" uni app-qianjin2"></icon>
					</view>
					
					<!-- #ifdef APP-PLUS -->
					<navigator>
						<view class="box_li myli" >
							<view>
								当前版本
							</view>
							<view>
								{{version}}
							</view>
						</view>
					</navigator>
					<!-- #endif -->
					
					<navigator url="">
						<view class="box_li myli" >
							<view>
								隐私与安全
							</view>
							<icon class=" uni app-qianjin2"></icon>
						</view>
					</navigator>
					
					<navigator url="">
						<view class="box_li myli" >
							<view>
								关于我们
							</view>
							<icon class=" uni app-qianjin2"></icon>
						</view>
					</navigator>
					
				</view>
			</view>
			<view class="logout">
				<form @submit="logoutSubmit">
					<button form-type="submit">退出</button>
				</form>
			</view>
			
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				storageSize:'',
				storageKeys:[],
				//#ifdef APP-PLUS
				version:plus.runtime.version,
				//#endif
			}
		},
		methods: {
			getStorageSize(){
				try {
				    const res = uni.getStorageInfoSync();
				    let size = res.currentSize;
					if (size < 1024) {
						this.storageSize = size + ' B';
					} else if (size/1024>=1 && size/1024/1024<1) {
						this.storageSize = Math.floor(size/1024*100)/100 + ' KB';
					} else if (size/1024/1024>=1) {
						this.storageSize = Math.floor(size/1024/1024*100)/100 + ' M';
					}
					for(var key in res.keys){
						if(res.keys[key]!='user'){
							this.storageKeys.push(res.keys[key]);
						}
					}
				} catch (e) {
				    
				}
			},
			cacheSize(){
				this.getStorageSize();
				uni.showModal({
				    title: '清空缓存',
				    content: '缓存大小 '+this.storageSize,
				    success: (res)=>{
				        if (res.confirm) {
				            this.clearCache();
				        } else if (res.cancel) {
				            //console.log('用户点击取消');
				        }
				    }
				});
			},
			clearCache(){
				for(var key in this.storageKeys){
					uni.removeStorageSync(this.storageKeys[key]);
				}
				uni.showToast({
					title:'缓存已清空',
					duration: 2000,
					icon: "none"
				})
			},
			logoutSubmit(){
				this.user = this.api.logout();
				this.api.request({url:'/api/v1/user/logout',method:'GET'
				}).then(res=>{
					uni.switchTab({
					    url: '/pages/my/my'
					});
				});
			},
		},
		onLoad() {
		}
	}
</script>

<style>
@import url("../my.css");
button{color: #777;background: #eee;}
</style>
